/* Copyright (C) 2005-2013, Unigine Corp. All rights reserved.
 *
 * File:    fragment_paint_light.h
 * Desc:    Mesh paint light shader
 * Version: 1.03
 * Author:  Alexander Zapryagaev <frustum@unigine.com>
 *
 * This file is part of the Unigine engine (http://unigine.com/).
 *
 * Your use and or redistribution of this software in source and / or
 * binary form, with or without modification, is subject to: (i) your
 * ongoing acceptance of and compliance with the terms and conditions of
 * the Unigine License Agreement; and (ii) your inclusion of this notice
 * in any version of this software that you use or redistribute.
 * A copy of the Unigine License Agreement is available by contacting
 * Unigine Corp. at http://unigine.com/
 */

/******************************************************************************\
*
* OpenGL/OpenGLES
*
\******************************************************************************/

#ifdef OPENGL || OPENGLES
	
	#ifndef FRAGMENT_PAINT_LIGHT
		#define FRAGMENT_PAINT_LIGHT
		
		uniform sampler2D s_texture_0;
		uniform sampler2D s_texture_1;
		uniform sampler2D s_texture_2;
		uniform sampler2D s_texture_3;
		
		uniform half4 detail_transform;
		uniform fixed diffuse_0_power;
		uniform fixed diffuse_1_power;
		uniform fixed diffuse_2_power;
		uniform fixed4 diffuse_0_color;
		uniform fixed4 diffuse_1_color;
		uniform fixed4 diffuse_2_color;
		
	#else
		
		#include <core/shaders/simple/mesh/fragment_paint_sample.h>
		
		#ifdef WORLD
			fixed3 color = diffuse.xyz * (saturate(dot(light_direction,normal)) * s_material_shading.x);
			color += specular.xyz * (pow(light_angle,s_material_shading.z) * s_material_shading.y);
		#else
			fixed attenuation = getAttenuate(s_texcoord_1);
			fixed3 color = diffuse.xyz * (saturate(dot(light_direction,normal)) * s_material_shading.x * attenuation);
			color += specular.xyz * (pow(light_angle,s_material_shading.z) * s_material_shading.y * attenuation);
		#endif
		
	#endif
	
/******************************************************************************\
*
* Direct3D11/Direct3D119
*
\******************************************************************************/

#elif DIRECT3D11 || DIRECT3D119
	
	#ifndef FRAGMENT_PAINT_LIGHT
		#define FRAGMENT_PAINT_LIGHT
		
		Texture2D s_texture_0 : register(t0);
		Texture2D s_texture_1 : register(t1);
		Texture2D s_texture_2 : register(t2);
		Texture2D s_texture_3 : register(t3);
		
		cbuffer shader_parameters {
			#ifdef OVERLAY_0 || OVERLAY_1 || MULTIPLY_0 || MULTIPLY_1
				float4 detail_transform;
			#endif
			float diffuse_0_power;
			float diffuse_1_power;
			float diffuse_2_power;
			float4 diffuse_0_color;
			float4 diffuse_1_color;
			float4 diffuse_2_color;
		};
		
	#else
		
		#include <core/shaders/simple/mesh/fragment_paint_sample.h>
		
		#ifdef WORLD
			half3 color = diffuse.xyz * (saturate(dot(light_direction,normal)) * s_material_shading.x);
			color += specular.xyz * (pow(light_angle,s_material_shading.z) * s_material_shading.y);
		#else
			half attenuation = getAttenuate(IN.texcoord_1);
			half3 color = diffuse.xyz * (saturate(dot(light_direction,normal)) * s_material_shading.x * attenuation);
			color += specular.xyz * (pow(light_angle,s_material_shading.z) * s_material_shading.y * attenuation);
		#endif
		
	#endif
	
#endif
